import { JSBridge } from "../JSBridge";

export default class WeiXinUtils {


    /** 跳转到其他小游戏 */
    static navigateToOtherGame(appid: string, query?: any, extraData?: any): void {
        let wx = JSBridge.getWXObj();
        if (!wx) return;
        console.log('尝试跳转到小游戏: ' + appid);
        wx.navigateToMiniProgram({
            appId: appid,
            path: '?' + query,
            extraData: extraData,
            success(res) {
                console.log('跳转到小游戏( ' + appid + ' )成功');
            }
        });
    }

    /** 监听游戏网络状态 */
    static listenNetworkStatusChange(callback: Function) {
        let wx = JSBridge.getWXObj();
        if (!wx) return;
        wx.onNetworkStatusChange((res) => {
            callback && callback(res.isConnected);
        })
    }

}
